/**
 *  Copyright (C) 2013  Piotr Szczepa�ski
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package edu.pw.elka.gtsna.centrality;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import edu.pw.elka.gtsna.coalitionalgames.CoalitionalGame;
import edu.pw.elka.gtsna.graph.Graph;

/**
 * @author Piotr Lech Szczepa�ski
 * @author P.Szczepanski@ii.pw.edu.pl 
 *
 */
public abstract class GroupNodeCentrality extends AbstractCentrality<Set<Integer>>  implements CoalitionalGame{

	protected Set<Integer> group;
    protected double centrality;
	
	public GroupNodeCentrality (Graph graph){
		super(graph);
		group = new HashSet<Integer>();
	}

	public abstract double computeCentrality(Set<Integer> group);
	
	@Override
	public double getCentrality (Set<Integer> group){
		return computeCentrality(group);
	}	
	
	@Override
	public void computeCentrality() {
		throw new UnsupportedOperationException();	
	}
	
    @Override
    public void printCentralities(){
        System.out.println("Group Betweenness Vertex Centrality");
        for(Integer vertex: group){
            System.out.print(vertex+" ");
        }
        System.out.println();
        System.out.println(centrality);
    }


	@Override
	public double v(Set<Integer> C) {
		return computeCentrality(C);
	}

	@Override
	public double MC(Set<Integer> C, int a) {
		reset();
		Set<Integer> S = new LinkedHashSet<Integer>(C);
		S.add(a);	
		return (v(S)-v(C));

	}
	
	@Override
	public double succesiveMC(int a) {
		return MC(group,a);
	}

	@Override
	public Set<Integer> getAgents() {
		return graph.getAllNodes();
	}

	@Override
	public int size() {
		return graph.getNumOfNodes();
	}
	
	@Override
	public void reset() {
		group.clear();
		centrality = 0;
	}
}
